import request from '@/utils/request'

// ==================== 编程题目 ====================

// 获取题目列表
export function getProblemList(params) {
  return request({
    url: '/v1/problems',
    method: 'get',
    params
  })
}

// 获取题目详情
export function getProblemDetail(id) {
  return request({
    url: `/v1/problems/${id}`,
    method: 'get'
  })
}

// 获取热门题目
export function getHotProblems(limit = 10) {
  return request({
    url: '/v1/problems/hot',
    method: 'get',
    params: { limit }
  })
}

// 获取推荐题目
export function getRecommendProblems(limit = 10) {
  return request({
    url: '/v1/problems/recommend',
    method: 'get',
    params: { limit }
  })
}

// 搜索题目
export function searchProblems(keyword, params) {
  return request({
    url: '/v1/problems/search',
    method: 'get',
    params: { keyword, ...params }
  })
}

// 按难度获取题目
export function getProblemsByDifficulty(difficulty, params) {
  return request({
    url: `/v1/problems/difficulty/${difficulty}`,
    method: 'get',
    params
  })
}

// 按标签获取题目
export function getProblemsByTag(tagId, params) {
  return request({
    url: `/v1/problems/tag/${tagId}`,
    method: 'get',
    params
  })
}

// 收藏题目
export function favoriteProblem(problemId) {
  return request({
    url: `/v1/problems/${problemId}/favorite`,
    method: 'post'
  })
}

// 取消收藏
export function unfavoriteProblem(problemId) {
  return request({
    url: `/v1/problems/${problemId}/unfavorite`,
    method: 'post'
  })
}

// 获取收藏题目
export function getFavoriteProblems(params) {
  return request({
    url: '/v1/problems/favorites',
    method: 'get',
    params
  })
}

// ==================== 代码提交 ====================

// 提交代码
export function submitCode(data) {
  return request({
    url: '/v1/submissions',
    method: 'post',
    data
  })
}

// 运行代码
export function runCode(data) {
  return request({
    url: '/v1/code/run',
    method: 'post',
    data
  })
}

// 获取提交记录
export function getSubmissionList(params) {
  return request({
    url: '/v1/submissions',
    method: 'get',
    params
  })
}

// 获取提交详情
export function getSubmissionDetail(id) {
  return request({
    url: `/v1/submissions/${id}`,
    method: 'get'
  })
}

// 获取我的提交记录
export function getMySubmissions(params) {
  return request({
    url: '/v1/submissions/my',
    method: 'get',
    params
  })
}

// 获取题目提交记录
export function getProblemSubmissions(problemId, params) {
  return request({
    url: `/v1/submissions/problem/${problemId}`,
    method: 'get',
    params
  })
}

// 获取提交统计
export function getSubmissionStatistics() {
  return request({
    url: '/v1/submissions/statistics',
    method: 'get'
  })
}

// ==================== 排行榜 ====================

// 获取总排行榜
export function getTotalRanking(params) {
  return request({
    url: '/v1/ranking/total',
    method: 'get',
    params
  })
}

// 获取题目排行榜
export function getProblemRanking(problemId, params) {
  return request({
    url: `/v1/ranking/problem/${problemId}`,
    method: 'get',
    params
  })
}

// 获取我的排名
export function getMyRanking() {
  return request({
    url: '/v1/ranking/my',
    method: 'get'
  })
}

// 获取周榜
export function getWeeklyRanking(params) {
  return request({
    url: '/v1/ranking/weekly',
    method: 'get',
    params
  })
}

// 获取月榜
export function getMonthlyRanking(params) {
  return request({
    url: '/v1/ranking/monthly',
    method: 'get',
    params
  })
}

// ==================== 题目分类和标签 ====================

// 获取题目分类
export function getProblemCategories() {
  return request({
    url: '/v1/problem-categories',
    method: 'get'
  })
}

// 获取题目标签
export function getProblemTags() {
  return request({
    url: '/v1/problem-tags',
    method: 'get'
  })
}

// ==================== 代码模板 ====================

// 获取代码模板
export function getCodeTemplate(problemId, language) {
  return request({
    url: `/v1/problems/${problemId}/template`,
    method: 'get',
    params: { language }
  })
}

// 获取支持的编程语言
export function getSupportedLanguages() {
  return request({
    url: '/v1/code/languages',
    method: 'get'
  })
}

// ==================== 讨论区 ====================

// 获取题目讨论
export function getProblemDiscussions(problemId, params) {
  return request({
    url: `/v1/discussions/problem/${problemId}`,
    method: 'get',
    params
  })
}

// 发表讨论
export function createDiscussion(data) {
  return request({
    url: '/v1/discussions',
    method: 'post',
    data
  })
}

// 回复讨论
export function replyDiscussion(discussionId, content) {
  return request({
    url: `/v1/discussions/${discussionId}/reply`,
    method: 'post',
    data: { content }
  })
}

// 点赞讨论
export function likeDiscussion(discussionId) {
  return request({
    url: `/v1/discussions/${discussionId}/like`,
    method: 'post'
  })
}

// ==================== 学习路径 ====================

// 获取学习路径
export function getLearningPaths() {
  return request({
    url: '/v1/learning-paths',
    method: 'get'
  })
}

// 获取路径详情
export function getLearningPathDetail(id) {
  return request({
    url: `/v1/learning-paths/${id}`,
    method: 'get'
  })
}

// 加入学习路径
export function joinLearningPath(pathId) {
  return request({
    url: `/v1/learning-paths/${pathId}/join`,
    method: 'post'
  })
}

// 获取我的学习路径
export function getMyLearningPaths() {
  return request({
    url: '/v1/learning-paths/my',
    method: 'get'
  })
}
